<?php
header("content-type:text/html;charset=utf-8");
    include_once 'conn/DbConn.php';
    class Digui extends DbConn{
        public static function getBbsInfo($condition = '')
        {
            $sql = "select * from testdg";
            if($condition){
                $sql = "select * from testdg where ".$condition;
            }
            $conn = DbConn::getInstance();
            $result = $conn->queryAll($sql);
            return $result;
        }
    }

    $cate_data = Digui::getBbsInfo();
    function getList($cate_data, $pid = 0, $spac = 0) {
        static $arr = array();
        foreach($cate_data as $key => $v){
            if($v['pid'] == $pid){
                $v['spac'] = $spac;
                $arr[] = $v;
                getList($cate_data, $v['id'], $spac+1);
            }
//            $spac = $spac+2;
//            $v['name'] = str_repeat('*',$spac).'--'.$v['name'];
        }
        return $arr;
    }
    $list = getList($cate_data);
//    echo '<pre>';
//    print_r($list);
    foreach($list as $v){
        //echo str_repeat('-',$v['spac']).$v['name'].'<br/>';
    }
$cate_data = Digui::getBbsInfo();
function cate_tree($cate_data,$pid = 0,$layout = 0){
        static $arr = array();
        foreach ($cate_data as $key => $v){
            if ($v['pid'] == $pid){
                $v['layout'] = $layout;
                $arr[] = $v;
                 cate_tree($cate_data,$v['id'],$layout+1);
             }
        }
         return $arr;
    }
    $res = cate_tree($cate_data); // 调用分类树函数
     foreach ($res as $v){
         if ($v['layout'] == 0){
             $indent = '┌';
         }else{
            $indent = '├'.str_repeat('─',$v['layout']);
         }
         echo "<p>{$indent}&nbsp;{$v['name']}</p>";
    }



